package edu.yourl.web.components;

import org.apache.wicket.ajax.AjaxRequestTarget;
import org.apache.wicket.ajax.markup.html.form.AjaxSubmitLink;
import org.apache.wicket.markup.html.form.Form;
import org.apache.wicket.markup.html.panel.Panel;

import edu.yourl.web.ResultsPage;
import edu.yourl.web.components.PropertyTextField;

public class SearchBar extends Panel {

	private static final long serialVersionUID = 1L;

	private String searchFriendsInput;
	
	@SuppressWarnings("serial")
	public SearchBar(String id) {
		super(id);

		Form<Void> searchFriendForm = new Form<Void>("searchForm") {
			@Override
			protected void onSubmit() {
				super.onSubmit();
				setResponsePage(new ResultsPage(getSearchFriendsInput()));
			}
		};
    	this.add(searchFriendForm);
    	searchFriendForm.add(new PropertyTextField<String>("searchFriendsInput", this));
    	AjaxSubmitLink searchSubmit = new AjaxSubmitLink("searchSubmit") {
			
			private static final long serialVersionUID = 1L;

			@Override
			protected void onSubmit(AjaxRequestTarget target, Form<?> form) {
				setResponsePage(new ResultsPage(getSearchFriendsInput()));
			}
		};
		searchFriendForm.add(searchSubmit);
	}
	
	public String getSearchFriendsInput() {
		return searchFriendsInput;
	}

	public void setSearchFriendsInput(String searchFriendsInput) {
		this.searchFriendsInput = searchFriendsInput;
	}

}
